package com.usian.mapper;


import com.usian.room.Room;
import com.usian.roomuser.RoomUser;
import com.usian.user.User;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface RoomMapper {
    @Insert("insert into room(room_user,room_name,room_number,room_date,password) values(#{roomUser},#{roomName},#{roomNumber},#{roomDate},#{password})")
    void insert(Room room);
    @Select("select * from room")
    List<Room> roomList();
    @Select("select * from user where id=#{roomUser}")
    User getUserById(Integer roomUser);
    @Select("SELECT room_id AS roomId, COUNT(user_id) AS count FROM room_user GROUP BY room_id")
    List<RoomUser> roomUser();
    @Select("select * from room where room_user=#{roomUser} and room_number=#{roomNumber}")
    Room getRoomById(Integer roomUser, Integer roomNumber);
    @Insert("insert into room_user(room_id,user_id) values (#{id},#{roomUser})")
    void insertRoomUser(Room room1);
    @Delete("delete from room where id=#{roomid}")
    void delRoom(Integer roomid);
    @Delete("delete from room_user where room_id=#{roomid}")
    void delRoomUser(Integer roomid);
    @Insert("insert into room_user(room_id,user_id) values (#{roomId},#{userId})")
    void addUser(RoomUser roomUser);
    @Select("select user_id from room_user where room_id=#{roomid}")
    List<RoomUser> roomUsers(Integer roomid);
    @Select("select * from room_user where room_id=#{roomId} and user_id=#{userId}")
    List<RoomUser> roomUsersId(Integer roomId, Integer userId);
    @Delete("delete from room_user where room_id=#{roomid} and user_id=#{userid}")
    void delRoomUsers(Integer roomid, Integer userid);
    @Select("select user_id AS id from room_user where room_id=#{roomid}")
    List<User> Users(Integer roomid);
}
